package com.example.SocialApplication.service;

import android.os.AsyncTask;
import com.example.SocialApplication.constants.URLs;
import com.example.SocialApplication.db.entity.User;
import com.google.gson.Gson;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by differ on 25.08.13.
 */
public class CallServiceAddFacebookUser extends AsyncTask<Void, Void, Integer> implements URLs {
    private User mUser;

    public CallServiceAddFacebookUser(User user) {
        mUser = user;
    }

    @Override
    protected Integer doInBackground(Void... params) {
        String result = "";
        String url = ADD_FB_USER_URL;
        Gson gson = new Gson();
        try {
            String res = gson.toJson(mUser);
            result = HttpServices.callHttpPutRequest(res, url);
        } catch (IOException e) {
            e.printStackTrace();
        }
        Integer res = 0;
        if (!result.equals("")) {
            try {
                res = gson.fromJson(result, Integer.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return res;
    }

    private List<NameValuePair> getListParams() {
        List<NameValuePair> param = new ArrayList<NameValuePair>();
        param.add(new BasicNameValuePair("firstName", mUser.getFirstName()));
        param.add(new BasicNameValuePair("lastName", mUser.getLastName()));
        param.add(new BasicNameValuePair("photo", mUser.getPhoto()));
//        param.add(new BasicNameValuePair("socialId", mUser.getSocialId().toString()));

        return param;
    }
}
